
#include "bsp_driver_spi.h"
/****************************************************                        
*				stm32f103x_bsp_init_SPI1_CC2500
* Description:	
* Arguments  :  
* Returns    :  
*****************************************************/
void stm32f103x_bsp_init_SPI2_CC2500(  ){


	SPI_InitTypeDef  SPIInit;

	RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);

	SPIInit.SPI_Direction			= SPI_Direction_2Lines_FullDuplex;
	SPIInit.SPI_Mode				= SPI_Mode_Master;
	SPIInit.SPI_DataSize			= SPI_DataSize_8b;
	SPIInit.SPI_CPOL				= SPI_CPOL_Low;
	SPIInit.SPI_CPHA				= SPI_CPHA_1Edge;
	SPIInit.SPI_NSS					= SPI_NSS_Soft;
	SPIInit.SPI_BaudRatePrescaler	= SPI_BaudRatePrescaler_256;
	SPIInit.SPI_FirstBit			= SPI_FirstBit_MSB;
	SPIInit.SPI_CRCPolynomial		= 7;
	SPI_Init(SPI2, &SPIInit);
}


/****************************************************                        
*				stm32f103x_bsp_SPI2_CC2500_WriteByte
* Description:	
* Arguments  :  
* Returns    :  
*****************************************************/
uint8_t stm32f103x_bsp_SPI2_CC2500_WriteByte( uint8_t uData ){

	/* Loop while DR register in not emplty */
	while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_TXE) == RESET);
	
	/* Send byte through the SPI1 peripheral */
	SPI_I2S_SendData(SPI2, uData);
	
	/* Wait to receive a byte */
	while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);
	
	/* Return the byte read from the SPI bus */
	return SPI_I2S_ReceiveData(SPI2);
}


/****************************************************                        
*				stm32f103x_bsp_init_SPI1_CC3000
* Description:	
* Arguments  :  
* Returns    :  
*****************************************************/
void stm32f103x_bsp_init_SPI1_CC3000( void ){

	SPI_InitTypeDef  SPIInit;
	
	RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI3, ENABLE);
	
	SPIInit.SPI_Direction			= SPI_Direction_2Lines_FullDuplex;
	SPIInit.SPI_Mode				= SPI_Mode_Master;
	SPIInit.SPI_DataSize		    = SPI_DataSize_8b;
	SPIInit.SPI_CPOL			    = SPI_CPOL_Low;
	SPIInit.SPI_CPHA			    = SPI_CPHA_2Edge;
	SPIInit.SPI_NSS					= SPI_NSS_Soft;
	SPIInit.SPI_BaudRatePrescaler   = SPI_BaudRatePrescaler_32;
	SPIInit.SPI_FirstBit			= SPI_FirstBit_MSB;
	SPIInit.SPI_CRCPolynomial		= 7;
	SPI_Init( SPI3, &SPIInit );

	SPI_Cmd(SPI3, ENABLE);	

}
	

